﻿using System;
using System.Text.RegularExpressions;

namespace mki.Backup.Helper.Extensions
{
	/// <summary>
	/// String extensions
	/// </summary>
	public static class StringExtension
	{
		#region Methods (3)

		// Public Methods (3) 

		/// <summary>
		/// Determines whether [is null or empty] [the specified source].
		/// </summary>
		/// <param name="source">The source.</param>
		/// <returns>
		///   <c>true</c> if [is null or empty] [the specified source]; otherwise, <c>false</c>.
		/// </returns>
		public static Boolean IsNullOrEmpty(this String source)
		{
			return String.IsNullOrWhiteSpace(source);
		}

		/// <summary>
		/// Es the mail address.
		/// </summary>
		/// <param name="source">The source.</param>
		/// <returns></returns>
		public static Boolean IsValidEmailAddress(this String source)
		{
			return Regex.IsMatch(source.Trim(), @"^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z-])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$");
		}

		/// <summary>
		/// Replaces the tokens.
		/// </summary>
		/// <param name="source">The source.</param>
		/// <returns></returns>
		public static String ReplaceTokens(this String source)
		{
			return source.Replace("{ServerName}", Environment.MachineName).Replace("{Date}", DateTime.Now.ToString("yyyyMMdd")).Replace("{Time}", DateTime.Now.ToString("HHmm"));
		}

		#endregion Methods
	}
}